package com.ukao.cashregister.adapter;

import android.content.Context;
import android.graphics.drawable.Drawable;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.mcxtzhang.commonadapter.rv.CommonAdapter;
import com.mcxtzhang.commonadapter.rv.ViewHolder;
import com.ukao.cashregister.R;
import com.ukao.cashregister.bean.BatchlistBean;
import com.ukao.cashregister.utils.CheckUtils;
import com.ukao.cashregister.utils.ImageUtils;
import com.ukao.cashregister.utils.MyDateUtils;

import java.util.List;

/**
 * Created by ukaodev on 2017/6/14.
 */

public class BatchDetailsAdapter extends CommonAdapter<BatchlistBean.ListBean> {



    public BatchDetailsAdapter(Context context, List<BatchlistBean.ListBean> item) {
        super(context, item, R.layout.adapter_batch_details);
    }
    private   boolean   isDetailsEnter;
    public  void  setbatchDetailsEnter(boolean isDetailsEnter){
        this.isDetailsEnter=isDetailsEnter;
    }
    @Override
    public void convert(ViewHolder holder, BatchlistBean.ListBean item) {


        LinearLayout   clothingLayout=(LinearLayout) holder.itemView.findViewById(R.id.clothing_layout);
        ImageView   selectCheckbox=(ImageView) holder.itemView.findViewById(R.id.select_checkbox);
        TextView   orderNumber=(TextView) holder.itemView.findViewById(R.id.order_number);
        TextView   clothingBarcode=(TextView) holder.itemView.findViewById(R.id.clothing_barcode);
        TextView   enterTime=(TextView) holder.itemView.findViewById(R.id.enter_time);
        TextView   serve=(TextView) holder.itemView.findViewById(R.id.serve);
        TextView   sortingText=(TextView) holder.itemView.findViewById(R.id.sortingText);
        TextView   state=(TextView) holder.itemView.findViewById(R.id.state);
        TextView   money=(TextView) holder.itemView.findViewById(R.id.money);
        TextView   productName=holder.getView(R.id.productName);
        state.setText(CheckUtils.isEmptyString(item.getStatusText()));
        money.setText(CheckUtils.isEmptyNumber(item.getSubtotal())+"");
        productName.setText(item.getProductName());
        orderNumber.setText(item.getOrderNo());
        clothingBarcode.setText(item.getScanCode());
        enterTime.setText(MyDateUtils.formatDataTime(item.getCreateTime()));
        serve.setText(item.getServiceName());
        if (isDetailsEnter){
            sortingText.setText(item.getSortingText());
        }else{
            sortingText.setVisibility(View.GONE);
        }


        if(item.isCheck()){
            Drawable drawable= mContext.getResources().getDrawable(R.drawable.check_box_check);
            selectCheckbox.setImageDrawable(drawable);
            holder.itemView.setBackgroundResource(R.color.back_blue);
        }else{
            Drawable drawable=  mContext.getResources().getDrawable(R.drawable.check_box_normal);
            /// 这一步必须要做,否则不会显示.
            selectCheckbox.setImageDrawable(drawable);
            holder.itemView.setBackgroundResource(R.color.white);
        }


        if (isDetailsEnter){
            ImageUtils.setViewWith(mContext, clothingLayout, 160, 0.11f);
            ImageUtils.setViewWith(mContext, orderNumber, 160, 0.14f);
            ImageUtils.setViewWith(mContext, clothingBarcode, 160, 0.14f);
            ImageUtils.setViewWith(mContext, enterTime, 160, 0.2f);
            ImageUtils.setViewWith(mContext, serve, 160, 0.1f);
            //  ImageUtils.setViewWith(mContext,color,160,0.1f);
            ImageUtils.setViewWith(mContext, state, 160, 0.1f);
            ImageUtils.setViewWith(mContext, money, 160, 0.1f);
            ImageUtils.setViewWith(mContext, sortingText, 160, 0.1f);
        }else{
                   ImageUtils.setViewWith(mContext,clothingLayout,160,0.12f);
        ImageUtils.setViewWith(mContext,orderNumber,160,0.15f);
        ImageUtils.setViewWith(mContext,clothingBarcode,160,0.17f);
        ImageUtils.setViewWith(mContext,enterTime,160,0.22f);
        ImageUtils.setViewWith(mContext,serve,160,0.11f);
        //  ImageUtils.setViewWith(activity,color,160,0.1f);
        ImageUtils.setViewWith(mContext,state,160,0.11f);
        ImageUtils.setViewWith(mContext,money,160,0.11f);
        }






    }








}
